<template>
    <div class="popup-container">
      <div class="popup">
        <h2>筛选结果</h2>
        <div class="image-container">
          <div v-for="image in displayedImages.data" >
            <img :src="image.wUrl" :alt="image.name" />
          </div>
        </div>
        <!-- <button @click="closePopup">关闭</button> -->
      </div>
    </div>
</template>
  
  <script>
  export default {
    props: {
      images: {
        type: [Array, Promise],
        required: true
      },
      isOpen: {
      type: Boolean,
      required: true,
      default:false
    }
    },
    data() {
      return {
        // isOpen: true,
        displayedImages: [] ,
        // isOpen:false
      };
    },
    watch: {
    async images(newImages) {
      this.displayedImages = await this.resolveImages(newImages);
      console.log('数据传到popup里面来啦'+this.displayedImages)
    }
  },
  computed: {
    popupVisible() {
      return this.isOpen;
    }
  },
    methods: {
      closePopup() {
      // this.$emit('update:isOpen',false);
      console.log('关闭时传递isOpen执行啦')
      // console.log('hahahahah'+this.displayedImages.data)
    },
      async resolveImages(images) {
      if (Array.isArray(images)) {
        // 如果 images 是一个数组，直接返回
        return images;
      } else if (images instanceof Promise) {
        // 如果 images 是一个 Promise 对象，等待解析后返回
        try {
          const resolvedImages = await images;
          return resolvedImages;
        } catch (error) {
          console.error(error);
          return [];
        }
      } else {
        // 其他情况返回空数组
        return [];
      }
    }
    }
  };
  </script>
  
  <style scoped>
  .popup-container {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.5);
    display: flex;
    justify-content: center;
    align-items: center;
  }
  
  .popup {
    background-color: #fff;
    padding: 20px;
    border-radius: 5px;
    text-align: center;
  }
  
  .image-container {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    margin-top: 20px;
  }
  
  .image-container img {
    width: 200px;
    height: 200px;
    margin: 10px;
  }
  </style>
  